package main

import (
	"flag"
	"fmt"
	"net"
)

func main() { 
	server := flag.Bool("S", false, "启动镜像端")
	mp := flag.String("b", ":6060", "镜像端-镜像地址B")
	bp := flag.String("X", ":6050", "镜像端-通道地址X")

	client := flag.Bool("C", false, "启动通道端")
	tp := flag.String("a", "", "中转端-目标地址A")
	cp := flag.String("x", "", "中转端-通道地址x")
	flag.Parse()

	if *server {
		tcpmp, err1 := net.ResolveTCPAddr("tcp", *mp)
		if err1 != nil {
			fmt.Printf("镜像地址(%v)错误：%v\n", *mp, err1)
			return
		}

		tcpbp, err2 := net.ResolveTCPAddr("tcp", *bp)
		if err2 != nil {
			fmt.Printf("通道地址(%v)错误：%v\n", *bp, err2)
			return
		}
		fmt.Println("启动镜像端...")
		s := NewServer(tcpbp, tcpmp)
		s.Start()
	}

	if *client {
		tcptp, err1 := net.ResolveTCPAddr("tcp", *tp)
		if err1 != nil {
			fmt.Printf("目标地址(%v)错误：%v\n", *tp, err1)
			return
		}

		tcpbp, err2 := net.ResolveTCPAddr("tcp", *cp)
		if err2 != nil {
			fmt.Printf("通道地址(%v)错误：%v\n", *cp, err2)
			return
		}
		fmt.Println("启动中转端...")
		c := NewClient(tcptp, tcpbp)
		c.Start()
	}

}
